package com.web44.springmvc.converter;


import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.net.http.HttpResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Title: MyDateConverter
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/1/15 10:28
 */
// Converter<
// 转换前的类型 即为页面中传来的数据 ,
// 转换后的类型 controller 适配器匹配的类型
// >
@Component
public class MyDateConverter implements Converter<String, Date> {
    @Override
    public Date convert(String dateString) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(dateString);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
